package Admin;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JPasswordField;
import java.awt.Color;
import java.awt.Font;

public class MemberJoin extends JPanel {
	JPanel contentPane;
	private JTextField mid;
	private JTextField irum;
	private JTextField tel;
	private JTextField address;
	private JTextField birth;
	private JTextField mail;
	private JLabel lblNewLabel;
	private JLabel lblPw;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;
	private JLabel label_5;
	private JLabel label_6;
	private JLabel label_7;
	private JRadioButton mail_y;
	private JRadioButton mail_n;
	private JRadioButton sms_n;
	private JRadioButton sms_y;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private boolean idck = false;
	private JPasswordField pwd;
	private ManageDTO dto;
	private JTextField tel2;
	private JTextField te3;
	private JTextField add1;
	private JTextField add2;
	private JTextField bir1;
	private JTextField bir2;
	private JTextField mail2;
	private JLabel lblNewLabel_1;
	private JLabel label;
	private JLabel label_8;
	private JLabel lblNewLabel_2;
	/**
	 * Create the panel.
	 */
	public MemberJoin(JPanel contentPane) {
		setBackground(Color.WHITE);
		this.contentPane = contentPane;
		setLayout(null);
		add(getMid());
		add(getIrum());
		add(getTel());
		add(getAddress());
		add(getBirth());
		add(getMail());
		add(getLblNewLabel());
		add(getLblPw());
		add(getLabel_1());
		add(getLabel_2());
		add(getLabel_3());
		add(getLabel_4());
		add(getLabel_5());
		add(getLabel_6());
		add(getLabel_7());
		add(getMail_y());
		add(getMail_n());
		add(getSms_n());
		add(getSms_y());
		add(getBtnNewButton());
		add(getBtnNewButton_1());
		add(getPwd());
		add(getTel2());
		add(getTe3());
		add(getAdd1());
		add(getAdd2());
		add(getBir1());
		add(getBir2());
		add(getMail2());
		add(getLblNewLabel_1());
		add(getLabel());
		add(getLabel_8());
		add(getLblNewLabel_2());
	}
	private JTextField getMid() {
		if (mid == null) {
			mid = new JTextField();
			mid.setBounds(163, 168, 116, 21);
			mid.setColumns(10);
		}
		return mid;
	}
	private JTextField getIrum() {
		if (irum == null) {
			irum = new JTextField();
			irum.setColumns(10);
			irum.setBounds(163, 227, 116, 21);
		}
		return irum;
	}
	private JTextField getTel() {
		if (tel == null) {
			tel = new JTextField();
			tel.setColumns(10);
			tel.setBounds(163, 258, 57, 21);
		}
		return tel;
	}
	private JTextField getAddress() {
		if (address == null) {
			address = new JTextField();
			address.setColumns(10);
			address.setBounds(163, 289, 91, 21);
		}
		return address;
	}
	private JTextField getBirth() {
		if (birth == null) {
			birth = new JTextField();
			birth.setColumns(10);
			birth.setBounds(163, 347, 57, 21);
		}
		return birth;
	}
	private JTextField getMail() {
		if (mail == null) {
			mail = new JTextField();
			mail.setColumns(10);
			mail.setBounds(163, 378, 116, 21);
		}
		return mail;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("ID");
			lblNewLabel.setBounds(94, 171, 57, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblPw() {
		if (lblPw == null) {
			lblPw = new JLabel("PW");
			lblPw.setBounds(94, 199, 57, 15);
		}
		return lblPw;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("이름");
			label_1.setBounds(94, 230, 57, 15);
		}
		return label_1;
	}
	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("연락처");
			label_2.setBounds(94, 261, 57, 15);
		}
		return label_2;
	}
	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("주소");
			label_3.setBounds(94, 292, 57, 15);
		}
		return label_3;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("생일");
			label_4.setBounds(94, 350, 57, 15);
		}
		return label_4;
	}
	private JLabel getLabel_5() {
		if (label_5 == null) {
			label_5 = new JLabel("문자동의");
			label_5.setBounds(518, 197, 57, 15);
		}
		return label_5;
	}
	private JLabel getLabel_6() {
		if (label_6 == null) {
			label_6 = new JLabel("메일동의");
			label_6.setBounds(518, 172, 57, 15);
		}
		return label_6;
	}
	private JLabel getLabel_7() {
		if (label_7 == null) {
			label_7 = new JLabel("메일");
			label_7.setBounds(94, 381, 57, 15);
		}
		return label_7;
	}
	private JRadioButton getMail_y() {
		if (mail_y == null) {
			mail_y = new JRadioButton("Y");
			mail_y.setBackground(Color.WHITE);
			mail_y.setSelected(true);
			buttonGroup.add(mail_y);
			mail_y.setBounds(587, 168, 33, 23);
		}
		return mail_y;
	}
	private JRadioButton getMail_n() {
		if (mail_n == null) {
			mail_n = new JRadioButton("N");
			mail_n.setBackground(Color.WHITE);
			buttonGroup.add(mail_n);
			mail_n.setBounds(634, 168, 40, 23);
		}
		return mail_n;
	}
	private JRadioButton getSms_n() {
		if (sms_n == null) {
			sms_n = new JRadioButton("N");
			sms_n.setBackground(Color.WHITE);
			buttonGroup_1.add(sms_n);
			sms_n.setBounds(634, 193, 40, 23);
		}
		return sms_n;
	}
	private JRadioButton getSms_y() {
		if (sms_y == null) {
			sms_y = new JRadioButton("Y");
			sms_y.setBackground(Color.WHITE);
			sms_y.setSelected(true);
			buttonGroup_1.add(sms_y);
			sms_y.setBounds(587, 193, 33, 23);
		}
		return sms_y;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("가입");
			btnNewButton.setBackground(Color.WHITE);
			btnNewButton.setEnabled(false);
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					joinmember();
				}
			});
			btnNewButton.setBounds(614, 244, 97, 23);
		}
		return btnNewButton;
	}
	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("중복검사");
			btnNewButton_1.setBackground(Color.WHITE);
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dto = new ManageDTO();
					
					if(mid.getText().equals("")){
						JOptionPane.showMessageDialog(MemberJoin.this, "ID를 입력 하세요");
					}else{
					
					if(dto.idck(mid.getText())){
						btnNewButton_1.setText("사용 가능");
						btnNewButton.setEnabled(true);
						idck = true;
					}else{
						btnNewButton_1.setText("중복 ID");
						btnNewButton.setEnabled(false);
						idck = false;
					}
					
					
					}
						
					
						
				
					
					
					
					
				}
			});
			btnNewButton_1.setBounds(302, 167, 97, 23);
		}
		return btnNewButton_1;
	}
	private JPasswordField getPwd() {
		if (pwd == null) {
			pwd = new JPasswordField();
			pwd.setBounds(163, 199, 116, 21);
		}
		return pwd;
	}
	
	
	
	
	public void joinmember(){
		MemberVo v = new MemberVo();
		dto = new ManageDTO();
		String gosns = "y";
		String gomail = "y";
		if(sms_n.isSelected()){
			gosns = "n";
		}
		if(mail_n.isSelected()){
			gomail = "n";
		}
		
		String fulladd = address.getText()+"-"+add1.getText()+"-"+add2.getText();
		String fullbirth = birth.getText() +"-"+bir1.getText()+"-"+bir2.getText(); 
		String fulltel =  tel.getText()+"-"+tel2.getText()+"-"+te3.getText();
		String fullmail = mail.getText()+"@"+mail2.getText(); 
		
		v.setMid(mid.getText());
		v.setPwd(pwd.getText());
		v.setAddress(fulladd);
		v.setBirth(fullbirth);
		v.setIrum(irum.getText());
		v.setTel(fulltel);
		
		v.setMail(fullmail);
		
		v.setGosns(gosns);
		v.setGomail(gomail);
		
		
		
		if(idck){
			if(dto.insertmember(v)){
				JOptionPane.showMessageDialog(this, "가입 성공");
			}else{
				JOptionPane.showMessageDialog(this, "가입 오류");
			}
		}else{
			JOptionPane.showMessageDialog(this, "중복체크를 해주세요");
		}
		
		
	}
	private JTextField getTel2() {
		if (tel2 == null) {
			tel2 = new JTextField();
			tel2.setColumns(10);
			tel2.setBounds(232, 258, 57, 21);
		}
		return tel2;
	}
	private JTextField getTe3() {
		if (te3 == null) {
			te3 = new JTextField();
			te3.setColumns(10);
			te3.setBounds(302, 258, 57, 21);
		}
		return te3;
	}
	private JTextField getAdd1() {
		if (add1 == null) {
			add1 = new JTextField();
			add1.setColumns(10);
			add1.setBounds(163, 316, 116, 21);
		}
		return add1;
	}
	private JTextField getAdd2() {
		if (add2 == null) {
			add2 = new JTextField();
			add2.setColumns(10);
			add2.setBounds(283, 316, 116, 21);
		}
		return add2;
	}
	private JTextField getBir1() {
		if (bir1 == null) {
			bir1 = new JTextField();
			bir1.setColumns(10);
			bir1.setBounds(232, 347, 57, 21);
		}
		return bir1;
	}
	private JTextField getBir2() {
		if (bir2 == null) {
			bir2 = new JTextField();
			bir2.setColumns(10);
			bir2.setBounds(302, 347, 57, 21);
		}
		return bir2;
	}
	private JTextField getMail2() {
		if (mail2 == null) {
			mail2 = new JTextField();
			mail2.setColumns(10);
			mail2.setBounds(302, 378, 116, 21);
		}
		return mail2;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("-");
			lblNewLabel_1.setBounds(221, 261, 15, 15);
		}
		return lblNewLabel_1;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("-");
			label.setBounds(292, 261, 15, 15);
		}
		return label;
	}
	private JLabel getLabel_8() {
		if (label_8 == null) {
			label_8 = new JLabel("@");
			label_8.setBounds(283, 381, 21, 15);
		}
		return label_8;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("회원 가입");
			lblNewLabel_2.setFont(new Font("굴림", Font.BOLD, 23));
			lblNewLabel_2.setBounds(94, 82, 232, 52);
		}
		return lblNewLabel_2;
	}
}
